2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "adiumPurpleCore.h"
19 #import "adiumPurpleAccounts.h"
20 #import "adiumPurpleBlist.h"
21 #import "adiumPurpleConnection.h"
22 #import "adiumPurpleConversation.h"
23 #import "adiumPurpleDnsRequest.h"
24 #import "adiumPurpleEventloop.h"
25 #import "adiumPurpleFt.h"
26 #import "adiumPurpleNotify.h"
27 #import "adiumPurplePrivacy.h"
28 #import "adiumPurpleRequest.h"
29 #import "adiumPurpleRoomlist.h"
30 #import "adiumPurpleSignals.h"
31 #import "adiumPurpleWebcam.h"
32 #import "adiumPurpleCertificateTrustWarning.h"
34 #import <AdiumLibpurple/SLPurpleCocoaAdapter.h>
35 #import "AILibpurplePlugin.h"
36 #import <AIUtilities/AIFileManagerAdditions.h>
39 // Debug ------------------------------------------------------------------------------------------------------
41 static void adiumPurpleDebugPrint(PurpleDebugLevel level, const char *category, const char *debug_msg)
44 if (!category) category = "general"; //Category can be nil
45 AILog(@"(Libpurple: %s) %s",category, debug_msg);
48 static PurpleDebugUiOps adiumPurpleDebugOps = {
52 PurpleDebugUiOps *adium_purple_debug_get_ui_ops(void)
54 return &adiumPurpleDebugOps;
58 // Core ------------------------------------------------------------------------------------------------------
60 extern gboolean purple_init_ssl_plugin(void);
61 extern gboolean purple_init_ssl_openssl_plugin(void);
62 extern gboolean purple_init_ssl_cdsa_plugin(void);
64 static void init_all_plugins()
66 AILog(@"adiumPurpleCore: load_all_plugins()");
68 //First, initialize our built-in plugins
69 purple_init_ssl_plugin();
71 purple_init_ssl_cdsa_plugin();
74 purple_init_ssl_openssl_plugin();
76 #warning No SSL plugin!
81 NSEnumerator *enumerator = [[SLPurpleCocoaAdapter libpurplePluginArray] objectEnumerator];
82 id <AILibpurplePlugin> plugin;
84 while ((plugin = [enumerator nextObject])) {
85 if ([plugin respondsToSelector:@selector(installLibpurplePlugin)]) {
86 [plugin installLibpurplePlugin];
91 PurplePlugin *cdsa_plugin = purple_plugins_find_with_name("CDSA");
94 purple_plugin_ipc_call(cdsa_plugin, "register_certificate_ui_cb", &ok, adium_query_cert_chain);
100 static void load_external_plugins(void)
103 NSEnumerator *enumerator = [[SLPurpleCocoaAdapter libpurplePluginArray] objectEnumerator];
104 id <AILibpurplePlugin> plugin;
106 while ((plugin = [enumerator nextObject])) {
107 if ([plugin respondsToSelector:@selector(loadLibpurplePlugin)]) {
108 [plugin loadLibpurplePlugin];
113 static void adiumPurplePrefsInit(void)
115 //Disable purple away handling - we do it ourselves
116 purple_prefs_set_bool("/purple/away/away_when_idle", FALSE);
117 purple_prefs_set_string("/purple/away/auto_reply","never");
119 //Disable purple idle reporting - we do it ourselves
120 purple_prefs_set_bool("/purple/away/report_idle", FALSE);
122 //Disable purple conversation logging
123 purple_prefs_set_bool("/purple/logging/log_chats", FALSE);
124 purple_prefs_set_bool("/purple/logging/log_ims", FALSE);
127 purple_prefs_set_bool("/purple/conversations/im/send_typing", TRUE);
129 //Use server alias where possible
130 purple_prefs_set_bool("/purple/buddies/use_server_alias", TRUE);
132 //Ensure we are using caching
133 purple_buddy_icons_set_caching(TRUE);
136 static void adiumPurpleCoreDebugInit(void)
139 AILog(@"adiumPurpleCoreDebugInit()");
140 purple_debug_set_ui_ops(adium_purple_debug_get_ui_ops());
143 //Initialize all external plugins.
147 /* The core is ready... finish configuring libpurple and its plugins */
148 static void adiumPurpleCoreUiInit(void)
150 bindtextdomain("pidgin", [[[NSBundle bundleWithIdentifier:@"im.pidgin.libpurple"] resourcePath] UTF8String]);
151 bind_textdomain_codeset("pidgin", "UTF-8");
152 textdomain("pidgin");
154 const char *preferredLocale = [[[[NSBundle bundleForClass:[SLPurpleCocoaAdapter class]] preferredLocalizations] objectAtIndex:0] UTF8String];
155 //We should be able to just do setlocale()... but it always returns NULL, which indicates failure
156 /* setlocale(LC_MESSAGES, preferredLocale); */
158 //So we'll set the environment variable for this process, which does work
159 setenv("LC_ALL", preferredLocale, /* overwrite? */ 1);
160 setenv("LC_MESSAGES", preferredLocale, /* overwrite? */ 1);
162 AILog(@"adiumPurpleCoreUiInit");
163 //Initialize the core UI ops
164 purple_blist_set_ui_ops(adium_purple_blist_get_ui_ops());
165 purple_connections_set_ui_ops(adium_purple_connection_get_ui_ops());
166 purple_privacy_set_ui_ops (adium_purple_privacy_get_ui_ops());
167 purple_accounts_set_ui_ops(adium_purple_accounts_get_ui_ops());
169 /* Why use Purple's accounts and blist list when we have the information locally?
170 * - Faster account connection: Purple doesn't have to recreate the local list
171 * - Privacy/blocking support depends on the accounts and blist files existing
173 * Another possible advantage:
174 * - Using Purple's own buddy icon caching (which depends on both files) allows us to avoid
175 * re-requesting icons we already have locally on some protocols such as AIM.
177 //Setup the buddy list; then load the blist.
178 purple_set_blist(purple_blist_new());
179 AILog(@"adiumPurpleCore: purple_blist_load()...");
182 //Configure signals for receiving purple events
183 configureAdiumPurpleSignals();
185 //Configure the GUI-related UI ops last
186 purple_roomlist_set_ui_ops (adium_purple_roomlist_get_ui_ops());
187 purple_notify_set_ui_ops(adium_purple_notify_get_ui_ops());
188 purple_request_set_ui_ops(adium_purple_request_get_ui_ops());
189 purple_xfers_set_ui_ops(adium_purple_xfers_get_ui_ops());
190 purple_dnsquery_set_ui_ops(adium_purple_dns_request_get_ui_ops());
192 adiumPurpleConversation_init();
195 initPurpleWebcamSupport();
198 load_external_plugins();
201 static void adiumPurpleCoreQuit(void)
207 static PurpleCoreUiOps adiumPurpleCoreOps = {
208 adiumPurplePrefsInit,
209 adiumPurpleCoreDebugInit,
210 adiumPurpleCoreUiInit,
214 PurpleCoreUiOps *adium_purple_core_get_ops(void)
216 return &adiumPurpleCoreOps;